﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using ZhimeiSoft.Framework.Client.Utils;
using ZhimeiSoft.Framework.Common.Enums;

using ZhimeiSoft.CharmManager.DOL;
using ZhimeiSoft.CharmManager.Client.Manager;
using ZhimeiSoft.Framework.Client.Base;

namespace ZhimeiSoft.CharmManager.Client.Forms.Control.ServiceItem
{
    public partial class frmServiceItemCategoryAdd : FormBase
    {
        public ControlClassModeEnum Flag { get; set; }
        private DBEntityServiceItemCategory _category;

        public frmServiceItemCategoryAdd()
        {
            InitializeComponent();
        }

        public frmServiceItemCategoryAdd(DBEntityServiceItemCategory category)
        {
            InitializeComponent();
            _category = category;
        }

        private void SetFormTitle()
        {
            if (Flag == ControlClassModeEnum.emInsert)
                this.Text = "新增分类";
            else if (Flag == ControlClassModeEnum.emEdit)
                this.Text = "修改分类";
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            string error = string.Empty;
            if (txtName.Text.Trim() == string.Empty)
            {
                MsgBox.MsgInfo("请输入分类名称。");
                return;
            }
            bool bReturn = false;
            _category.SNAME = txtName.Text;
            if (Flag == ControlClassModeEnum.emInsert)
            {
                bReturn = BussinessProxyManager.Instance.InsertServiceItemCategory(_category, out error);
            }
            else if (Flag == ControlClassModeEnum.emEdit)
            {
                bReturn = BussinessProxyManager.Instance.UpdateServiceItemCategory(_category, out error);
            }
            if (bReturn == false)
            {
                MsgBox.MsgErr(error);
                return;
            }
            MsgBox.MsgInfo("保存成功。");
            this.DialogResult = DialogResult.OK;
        }

        private void frmServiceItemCategoryAdd_Shown(object sender, EventArgs e)
        {
            this.SetFormTitle();
            if (Flag == ControlClassModeEnum.emEdit)
            {
                txtName.Text = _category.SNAME;
            }
        }
    }
}
